﻿//------------------------------------------------------------------------------
// 创建标识: Copyright (C) 2010 Socansoft.com 版权所有
// 创建描述: SocanCode代码生成器 V4.3.3.6 自动创建于 2010/4/7 16:16:45
//
// 功能描述: 
//
// 修改标识: 
// 修改描述: 
//------------------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace IBSSqlServerDAL
{
    /// <summary>
    /// 数据访问类 TimeTableDetail
    /// </summary>
    public class TimeTableDetail : DALHelper
    {
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(IBSModel.TimeTableDetail model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("INSERT INTO TimeTableDetail(");
            strSql.Append("OwnTimeTable,RowNUM,ColNUM,Content)");
            strSql.Append(" VALUES (");
            strSql.Append("@in_OwnTimeTable,@in_RowNUM,@in_ColNUM,@in_Content)");
            DbParameter[] cmdParms = {
                                         IBS_TestHelper.CreateInDbParameter("@in_OwnTimeTable", DbType.Int32, model.OwnTimeTable),
                                         IBS_TestHelper.CreateInDbParameter("@in_RowNUM", DbType.Int32, model.RowNUM),
                                         IBS_TestHelper.CreateInDbParameter("@in_ColNUM", DbType.Int32, model.ColNUM),
                                         IBS_TestHelper.CreateInDbParameter("@in_Content", DbType.AnsiString, model.Content)};

            return IBS_TestHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(IBSModel.TimeTableDetail model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("UPDATE TimeTableDetail SET ");
            strSql.Append("OwnTimeTable=@in_OwnTimeTable,");
            strSql.Append("RowNUM=@in_RowNUM,");
            strSql.Append("ColNUM=@in_ColNUM,");
            strSql.Append("Content=@in_Content");
            strSql.Append(" WHERE ID=@in_ID");
            DbParameter[] cmdParms = {
                                         IBS_TestHelper.CreateInDbParameter("@in_OwnTimeTable", DbType.Int32, model.OwnTimeTable),
                                         IBS_TestHelper.CreateInDbParameter("@in_RowNUM", DbType.Int32, model.RowNUM),
                                         IBS_TestHelper.CreateInDbParameter("@in_ColNUM", DbType.Int32, model.ColNUM),
                                         IBS_TestHelper.CreateInDbParameter("@in_Content", DbType.AnsiString, model.Content),
                                         IBS_TestHelper.CreateInDbParameter("@in_ID", DbType.Int32, model.ID)};
            return IBS_TestHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public int Delete(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("DELETE FROM TimeTableDetail ");
            strSql.Append(" WHERE ID=@in_ID");
            DbParameter[] cmdParms = {
                                         IBS_TestHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};

            return IBS_TestHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT COUNT(1) FROM TimeTableDetail");
            strSql.Append(" WHERE ID=@in_ID");
            DbParameter[] cmdParms = {
                                         IBS_TestHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};

            object obj = IBS_TestHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), cmdParms);
            return IBS_TestHelper.GetInt(obj) > 0;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public IBSModel.TimeTableDetail GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM TimeTableDetail ");
            strSql.Append(" WHERE ID=@in_ID");
            DbParameter[] cmdParms = {
                                         IBS_TestHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};

            IBSModel.TimeTableDetail model = null;
            using (DbDataReader dr = IBS_TestHelper.ExecuteReader(CommandType.Text, strSql.ToString(), cmdParms))
            {
                while (dr.Read())
                {
                    model = GetModel(dr);
                }
                return model;
            }
        }

        /// <summary>
        /// 获取泛型数据列表
        /// </summary>
        public List<IBSModel.TimeTableDetail> GetList()
        {
            StringBuilder strSql = new StringBuilder("SELECT * FROM TimeTableDetail");
            using (DbDataReader dr = IBS_TestHelper.ExecuteReader(CommandType.Text, strSql.ToString(), null))
            {
                List<IBSModel.TimeTableDetail> lst = GetList(dr);
                return lst;
            }
        }

        /// <summary>
        /// 得到数据条数
        /// </summary>
        public int GetCount(string condition)
        {
            return IBS_TestHelper.GetCount("TimeTableDetail", condition);
        }

        /// <summary>
        /// 分页获取泛型数据列表
        /// </summary>
        public List<IBSModel.TimeTableDetail> GetPageList(int pageSize, int pageIndex, string fldSort, bool fldDir, string condition)
        {
            using (DbDataReader dr = IBS_TestHelper.GetPageList("TimeTableDetail", pageSize, pageIndex, fldSort, fldDir, condition))
            {
                List<IBSModel.TimeTableDetail> lst = GetList(dr);
                return lst;
            }
        }

        #region -------- 私有方法，通常情况下无需修改 --------

        /// <summary>
        /// 由一行数据得到一个实体
        /// </summary>
        private IBSModel.TimeTableDetail GetModel(DbDataReader dr)
        {
            IBSModel.TimeTableDetail model = new IBSModel.TimeTableDetail();
            model.ID = IBS_TestHelper.GetInt(dr["ID"]);
            model.OwnTimeTable = IBS_TestHelper.GetInt(dr["OwnTimeTable"]);
            model.RowNUM = IBS_TestHelper.GetInt(dr["RowNUM"]);
            model.ColNUM = IBS_TestHelper.GetInt(dr["ColNUM"]);
            model.Content = IBS_TestHelper.GetString(dr["Content"]);
            return model;
        }

        /// <summary>
        /// 由DbDataReader得到泛型数据列表
        /// </summary>
        private List<IBSModel.TimeTableDetail> GetList(DbDataReader dr)
        {
            List<IBSModel.TimeTableDetail> lst = new List<IBSModel.TimeTableDetail>();
            while (dr.Read())
            {
                lst.Add(GetModel(dr));
            }
            return lst;
        }

        #endregion

        #region User Code

        public IList<IBSModel.TimeTableDetail> GetModelByMainId(int mainID)
        {
            StringBuilder strSql = new StringBuilder("SELECT * FROM TimeTableDetail ");
            strSql.Append(" WHERE OwnTimeTable = @ownTimeTable ");

            DbParameter[] cmdParms = {
                                         IBS_TestHelper.CreateInDbParameter("@ownTimeTable", DbType.Int32, mainID)};

            using (DbDataReader dr = IBS_TestHelper.ExecuteReader(CommandType.Text, strSql.ToString(), cmdParms))
            {
                List<IBSModel.TimeTableDetail> lst = GetList(dr);
                return lst;
            }
        }

        #endregion
    }
}